package com.bdqn.ThymeleafJPA.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.bdqn.ThymeleafJPA.config.Constants;
import com.bdqn.ThymeleafJPA.entity.Role;
import com.bdqn.ThymeleafJPA.service.IRoleService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
@RequestMapping("/role")
public class RoleController {
    @Resource
    private IRoleService roleService;

    @RequestMapping("/list")
    public String list(Model model, String roleName, @RequestParam(defaultValue = "1") Integer pageIndex){
        QueryWrapper<Role> qw=new QueryWrapper<>();
        if(roleName!=null && !"".equals(roleName)){
            qw.like("role_name",roleName);
        }
        Page<Role> rolePage= new Page<>(pageIndex, Constants.ROLE_PAGE_SIZE);
        IPage<Role> rolePager = roleService.page(rolePage,qw);
        model.addAttribute("roleName",roleName);
        model.addAttribute("rolePager",rolePager);
        return "role/list";
    }
}
